{php $top_name="订单结算";}{template "header.html"}
<script type="text/javascript">
$(function(){
    {if $is_shipping}
    dr_load_address();
    {else}
    dr_get_order_price();
    {/if}
    $('.online-payment').hover(function(){
        $(this).addClass('payment-item-hover');
    },function(){
        $(this).removeClass('payment-item-hover');
    });
    $(".payment-item").click(function(){
        var id = $(this).attr("pid");
        $(".payment-item").removeClass("default");
        $(".payment-item").addClass("grey-mint");
        $(this).addClass("default");
        // 赋值
        $("#dr_pay_type").val(id);
    });
});
function dr_get_order_price() {
	$.ajax({type: "POST", url: "{dr_url('order/home/price', array('is_shipping' => $is_shipping))}&city="+$("#dr_shipping_city").val(), data: {data: {json_encode($order_list)}}, dataType:"json",
        success: function (data) {
			if (data.status == 1) {
				$("#dr_total_price").html(data.price);
				$("#dr_total_score").html(data.score);
				$.each(data.info, function(n, value) {
					$("#dr_order_yunfei_"+n).html(value.yunfei);				
					$("#dr_order_youhui_"+n).html(value.youhui);
					$("#dr_order_total_"+n).html(value.price);
					$("#dr_order_total_score_"+n).html(value.score);
				});
			} else {
				dr_tips(data.code);
			}
        }
    });
}
function dr_load_address() {
    $("#dr_address_list").html('<img src="{THEME_PATH}admin/images/loading-mini.gif" />');
    $.ajax({type: "GET", url: "{dr_url('order/address/index')}&id="+$("#dr_shipping_id").val()+"&"+Math.random(), dataType:"jsonp",
        success: function (data) {
            $("#dr_address_list").html(data.html);
			// 重新计算运费和订单总额
			dr_get_order_price();
        }
    });
}
function dr_add_address() {
    var url = "{dr_url('order/address/add')}";
    art.dialog.open(url, {title: "新增收货地址",
        ok: function () {
            var iframe = this.iframe.contentWindow;
            if (!iframe.document.body) {
                alert('iframe loading')
                return false;
            };
            var data = iframe.$('#myform').serialize();
            $.ajax({type: "GET", url:url, data:data+'&submit=1', dataType:'jsonp', success: function (data) {
                if (data.status == 1) {
                    iframe.art.dialog.close();
                    dr_tips('添加成功', 3, 1);
                    dr_load_address();
                } else {
                    dr_tips(data.code);
                }
            }});
            return false;
        },
        cancel: true
    });
}
function dr_edit_address(id) {
    var url = "{dr_url('order/address/edit')}&id="+id;
    art.dialog.open(url, {title: "修改收货地址",
        ok: function () {
            var iframe = this.iframe.contentWindow;
            if (!iframe.document.body) {
                alert('iframe loading')
                return false;
            };
            var data = iframe.$('#myform').serialize();
            $.ajax({type: "GET", url:url, data:data+'&submit=1', dataType:'jsonp', success: function (data) {
                if (data.status == 1) {
                    dr_tips('修改成功', 3, 1);
                    iframe.art.dialog.close();
                    dr_load_address();
                } else {
                    dr_tips(data.code);
                }
            }});
            return false;
        },
        cancel: true
    });
}
function dr_del_address(id) {
    $.ajax({type: "GET", url:"{dr_url('order/address/del')}&id="+id, dataType:'jsonp', success: function (data) {
        if (data.status == 1) {
            dr_tips('删除成功', 3, 1);
            dr_load_address();
        } else {
            dr_tips(data.code);
        }
    }});
}
function dr_set_address(id) {
    $.ajax({type: "GET", url:"{dr_url('order/address/set_default')}&id="+id, dataType:'jsonp', success: function (data) {
        if (data.status == 1) {
            dr_tips('设置成功', 3, 1);
        } else {
            dr_tips(data.code);
        }
    }});
}
</script>

<form action="" id="myform" method="post">
<div class="page-container">
    <div class="page-content-wrapper">
        <div class="page-content bg-h">
            <div class="container  pd-0">


                    <div class="page-content-inner">

                        {if $is_shipping}
                        <div class="portlet light cart-table">
                            <div class="portlet-title">
                                <div class="caption">收货人信息</div>
                                <div class="actions">
                                    <a class="btn green" onclick="dr_add_address()" href="javascript:;">
                                        <i class="fa fa-plus"></i> 新增收货人
                                    </a>
                                </div>
                            </div>
                            <div class="portlet-body">
                                <div class="mt-element-list">
                                    <div class="mt-list-container list-simple" style="border:none;padding:0;">
                                        <ul id="dr_address_list">


                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                        {/if}

                        <div class="portlet light cart-table">
                            <div class="portlet-title">
                                <div class="caption">支付方式</div>
                                <div class="actions">
                                </div>
                            </div>
                            <div class="portlet-body">
                                <input type="hidden" name="data[pay_type]" id="dr_pay_type" value="{$pay_value}">
                                {loop $pay_type $t}
                                <a pid="{$t.id}" class="btn  {if $t.id==$pay_value}default{else}grey-mint{/if} payment-item online-payment" href="javascript:;">{$t.name}</a>
                                {/loop}
                            </div>
                        </div>


                        {loop $order_list $u $store}
                        <div class="portlet light cart-table">
                            <div class="portlet-title">
                                <div class="caption">商家：<a href="{$store.url}" target="_blank">{$store.name}</a></div>
                                <div class="actions">
                                </div>
                            </div>
                            <div class="portlet-body">
                                {loop $store.goods $t}
                                <div class="card-order-list">
                                    <div class="cart-order-info">
                                        <div class="media">
                                            <a class="pull-left" href="$t.url}" target="_blank">
                                                <img src="{dr_thumb($t.thumb, 55, 55)}" width="55" height="55">
                                            </a>
                                            <div class="media-body">
                                                <h5 class="media-heading"><a href="{$t.url}" target="_blank">{$t.title}</a></h5>
                                                <div class="cart-order-sx">
                                                    {loop $t.sku $sname $svalue}
                                                    <lable>{$sname}：{$svalue}&nbsp;&nbsp;</lable>
                                                    {/loop}
                                                    <lable>{if $t.use}x{$t.quantity}{else}<span style="color:#e4393c">无货</span>{/if}</lable>
                                                    <lable>{if $t.order_score}{intval($t.price)}{SITE_SCORE}{else}￥{number_format($t.price, 2)}元{/if}</lable>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                {/loop}

								<div class="cart-order-field">
									<textarea placeholder="限45个字（定制类商品，请将购买需求在备注中做详细说明）" class="form-control" name="data[{$u}][buy_note]"></textarea>
									{if $myfield}
									{str_replace('data[', 'data['.$u.'][', $myfield)}
									{/if}
								</div>

                                <div class="cart-order-js ">
                                    运费：￥<span class="price" id="dr_order_yunfei_{$u}">{number_format($store.yunfei, 2)}</span>元<br>
                                    店铺合计(含运费)：￥<span class="price" id="dr_order_total_{$u}">0.00</span>元   <span class="price" id="dr_order_total_score_{$u}">0</span>{SITE_SCORE}
                                </div>

                            </div>
                        </div>
                        {/loop}




                    </div>
            </div>
        </div>
    </div>
</div>

<div class="footFixed" id="foot_btn_fixed">
    <div class="reply_hd clearfix display1" id="reply_hd">
        <lable class="pull-left" style="padding-left:10px;">应付总额：<strong style="color: red">￥<span id="dr_total_price">0.00</span>元</strong>   <strong style="color: red"><span id="dr_total_score">0</span>{SITE_SCORE}</strong></lable>
        <lable class="pull-right"><button id="openReply" type="submit" class="btn comment-post-div"><i class="fa fa-edit"></i> 提交订单</button></lable>
    </div>
</div>
</form>
{template "footer.html"}